package com.itheima.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.commit.R;
import com.itheima.dto.DishDto;
import com.itheima.pojo.Category;
import com.itheima.pojo.Dish;
import com.itheima.service.CategoryService;
import com.itheima.service.DishFlavorService;
import com.itheima.service.DishService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dish")
@Slf4j
public class DishController {
    @Autowired
    private DishFlavorService dishFlavorService;
    @Autowired
    private DishService dishService;
    @Autowired
    private CategoryService categoryService;

    @PostMapping
    public R<String> add(@RequestBody DishDto dishDto){
        log.info("dishDao");
        return dishService.add(dishDto);
    }

    @GetMapping("/page")
    public R<IPage> selectP(Integer page, Integer pageSize, String name){
        return dishService.selectP(page,pageSize,name);
    }

    @GetMapping("/{id}")
    public R<DishDto> get(@PathVariable Long id){
        return dishService.get(id);
    }
    @PutMapping
    public R<String> update(@RequestBody DishDto dishDto){
        return dishService.update(dishDto);
    }
    @PostMapping("/status/{s}")
    public R<String> upda(@PathVariable int s, Long[] ids){
        return dishService.upda(s,ids);
    }
    @DeleteMapping
    public R<String> delete(Long[] ids){
        return dishService.delete(ids);
    }
    @GetMapping("/list")
    public R<List<DishDto>> select(Dish dish){
        return dishService.list(dish);
    }
}
